package com.wf.classRoomTest;

public class Demo {


    public static void main(String[] args) {
        int[] nums = new int[]{1, 3, 4, 5, 6, 8, 12, 14, 16};
        int left = 0;
        int right = nums.length - 1;
        System.out.println(search(nums, left, right, 8));
    }

    public static int  search(int[] nums, int left, int right, int target) {
        while (left <= right) {
            int mid = left + (right - left) / 2;
            if (nums[mid] < target) {
                left = mid + 1;
            } else if (nums[mid] > target) {
                right = mid - 1;
            } else {
                return mid; 

            }
        }
        return -1;

    }
}

